package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.netty.handler.codec.mqtt.MqttMessageBuilders;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	@PostMapping(value = "/uploadTrack")
	public Result<UploadTrackVo> uploadTrack(MultipartFile file) {
		UploadTrackVo uploadTrackVo = trackInfoService.uploadTrack(file) ;
		return Result.build(uploadTrackVo , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@PostMapping(value = "/saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
		trackInfoService.saveTrackInfo(trackInfoVo) ;
		return Result.build(null , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin
	@PostMapping(value = "/findUserTrackPage/{page}/{limit}")
	public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable(value = "page") Integer pageNo ,
														@PathVariable(value = "limit")Integer pageSize ,
														@RequestBody TrackInfoQuery trackInfoQuery) {
		IPage<TrackListVo> page = trackInfoService.findUserTrackPage(pageNo , pageSize , trackInfoQuery) ;
		return Result.build(page , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/getTrackInfo/{id}")
	public Result<TrackInfo> getTrackInfo(@PathVariable(value = "id") Long id) {
		TrackInfo trackInfo = trackInfoService.getById(id);
		return Result.build(trackInfo , ResultCodeEnum.SUCCESS) ;
	}

	@PutMapping(value = "/updateTrackInfo/{id}")
	public Result updateTrackInfo(@PathVariable(value = "id") Long id , @RequestBody TrackInfoVo trackInfoVo) {
		trackInfoService.updateTrackInfo(id , trackInfoVo) ;
		return Result.build(null , ResultCodeEnum.SUCCESS) ;
	}

	@DeleteMapping(value = "/removeTrackInfo/{id}")
	public Result removeTrackInfo(@PathVariable(value = "id") Long id) {
		trackInfoService.removeTrackInfo(id) ;
		return Result.build(null , ResultCodeEnum.SUCCESS) ;
	}

	@GuiGuLogin(required = false)
	@GetMapping(value = "/findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage( @PathVariable(value = "albumId") Long albumId ,
			@PathVariable(value = "page") Integer pageNo ,
			@PathVariable(value = "limit") Integer pageSize) {
		IPage<AlbumTrackListVo> page = trackInfoService.findAlbumTrackPage(albumId , pageNo , pageSize) ;
		return Result.build(page , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/getTrackStatVo/{trackId}")
	public Result<TrackStatVo> getTrackStatVo(@PathVariable(value = "trackId") Long trackId) {
		TrackStatVo trackStatVo = trackInfoService.getTrackStatVo(trackId);
		return Result.build(trackStatVo , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/findUserTrackPaidList/{trackId}")
	public Result<List<TrackPayVo>> findUserTrackPaidList(@PathVariable(value = "trackId") Long trackId) {
		List<TrackPayVo> list = trackInfoService.findUserTrackPaidList(trackId) ;
		return Result.build(list , ResultCodeEnum.SUCCESS) ;
	}

	@GetMapping(value = "/findPaidTrackInfoList/{trackId}/{trackCount}")
	public Result<List<TrackInfo>> findPaidTrackInfoList(@PathVariable(value = "trackId") Long tracKId ,
														 @PathVariable(value = "trackCount") Integer trackCount) {
		List<TrackInfo> trackInfoList = trackInfoService.findPaidTrackInfoList(tracKId, trackCount) ;
		return Result.build(trackInfoList , ResultCodeEnum.SUCCESS) ;
	}

}

